﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.PrettyPrinter;

namespace Genuilder.Extensibility.NRefactory
{
	public static class NRefactoryExtensions
	{
		public static string GetNameOrVoid(this ICSharpCode.NRefactory.Ast.TypeReference typeReference)
		{
			if(typeReference.Type == "System.Void")
				return "void";
			return typeReference.ToString();
		}
		public static string GetNameWithoutNamespace(this ICSharpCode.NRefactory.Ast.TypeReference typeReference)
		{
			return typeReference.ToString().Split('.').Last();
		}
		public static string WithoutNamespace(this string name)
		{
			return name.Split('.').Last();
		}
		public static bool IsVoid(this ICSharpCode.NRefactory.Ast.TypeReference typeReference)
		{
			return typeReference.Type == "System.Void";
		}
		public static string ToCs(this INode node)
		{
			CSharpOutputVisitor csVisitor =new CSharpOutputVisitor();
			node.AcceptVisitor(csVisitor, null);
			return csVisitor.Text;
		}
	}
}
